﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Config;
using DataAccess;

namespace Manager
{
    public partial class Manager : System.Web.UI.MasterPage
    {
        //Lấy link hiện tại để so sánh
        string urlCurr1 = HttpContext.Current.Request.Url.AbsoluteUri.Substring(HttpContext.Current.Request.Url.AbsoluteUri.LastIndexOf('/'));

        protected void Page_Load(object sender, EventArgs e)
        {
            Reset_Control();
            if (!IsPostBack)
            {
                CheckLoginSession();
            }
            Load_Info();
        }
        /// <summary>
        /// Kiểm tra login
        /// </summary>
        public void CheckLoginSession()
        {
            try
            {
                HttpContext.Current.Session[Constants.SESSION_CURRENT_URL] = HttpContext.Current.Request.Url.AbsoluteUri;

                if (HttpContext.Current.Session[Constants.SESSION_USERID] == null)
                {
                    HttpContext.Current.Response.Redirect("Login.aspx");
                }
            }
            catch (Exception)
            {
                HttpContext.Current.Response.Redirect("Login.aspx");
            }
        }

        private void Reset_Control()
        {
            dashboard.Visible = false;
            catalog.Visible = false;
            news.Visible = false;
            user.Visible = false;
            addUser.Visible = false;
            system.Visible = false;
        }

        private void Load_Info()
        {
            int userID = Convert.ToInt32(Session[Config.Constants.SESSION_USERID]);
            UserInfo userInfo = UserData.SelectByUserID(userID);

            lblName.Text = userInfo.FullName;
                dashboard.Visible = true;
                catalog.Visible = true;
                news.Visible = true;
                user.Visible = true;
                addUser.Visible = true;
                system.Visible = true;
                notice.Visible = true;
                lblUser.Text = "<a href=\"UserManager.aspx\">Quản lý Thành viên</a>";
           
        }

        protected void lbtLogout_Click(object sender, EventArgs e)
        {
            Session[Constants.SESSION_USERID] = null;
            Response.Redirect("Login.aspx");
        }
    }
}